package com.candoit.webapps.pricing.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "centro_costos")
public class CentroCostos implements Serializable {

	private static final long serialVersionUID = -592404254224778189L;
	
	public static final Integer UTECO_CODE = 16;
	
	public static final Integer NEWLONG_CODE = 17;
	
	public static final Integer EMPAQUETADORA_CODE = 43;
	
	public static final Integer CORTE_DE_BOBINA_A_BOBINA_CODE = 41;
	
	public static final Integer CORTE_DE_BOBINA_A_PLIEGO_CODE = 42;
	
	public static final Integer GUILLOTINA = 18;
	
	public static final Integer IMPRESORA = 19;
	
	public static final Integer TROQUELADO = 21;
	
	public static final Integer ESTAMPADORA = 39;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Integer id;
	
	@Column(name = "nombre")
	private String nombre;
	
	@ManyToOne
	@JoinColumn(name="id_categoria", referencedColumnName="id")
	private Categoria categoria;
	
	@Column(name = "factor")
	private Double factor = 0.00d;
	
	@ManyToOne
	@JoinColumn(name="id_criterio", referencedColumnName="id", nullable = true)
	private CriterioDistribucion criterio;
	
	//TODO: Delete this and its table
	@ManyToMany
	@JoinTable(name="centros_maquinas",
	  			joinColumns=
	  					@JoinColumn(name="id_cc", referencedColumnName="id"),
	  					inverseJoinColumns=@JoinColumn(name="id_maquina", referencedColumnName="id")
	        	)
	private List<Maquina> maquinas;
	
	@Transient
	private String idStr;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public Categoria getCategoria() {
		return categoria;
	}

	public void setCategoria(Categoria categoria) {
		this.categoria = categoria;
	}
	
	public double getFactor() {
		return factor;
	}

	public void setFactor(double factor) {
		this.factor = factor;
	}
	
	public List<Maquina> getMaquinas() {
		return maquinas;
	}

	public void setMaquinas(List<Maquina> maquinas) {
		this.maquinas = maquinas;
	}

	public void setFactor(Double factor) {
		this.factor = factor;
	}
	
	public String getIdStr() {
		idStr = String.valueOf(id);
		return idStr;
	}

	public void setIdStr(String idStr) {
		this.idStr = idStr;
	}	

	public CriterioDistribucion getCriterio() {
		return criterio;
	}

	public void setCriterio(CriterioDistribucion criterio) {
		this.criterio = criterio;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof CentroCostos && ((CentroCostos)obj).getId().equals(this.id)){
			return true;
		}
		return false;
	}
	
	@Override
	public String toString(){
		return this.nombre;
	}
	
}
